<style>
 td.tbW {
 	width:100px;
 }
</style>
<script type="text/javascript">
var i = 0, getModelMapRow = function() {
	return {
		id:'',
		mappedBy : '',
		mappedType : "OneToMany"
	};
};
function addModelMap() {
	codeModelMapSetList.datagrid("appendRow", getModelMapRow());
}
function removeModelMap() {
	var rows = codeModelMapSetList.datagrid('getChecked');
	printLog(rows);
    if (rows&&rows.length>0){
        $.messager.confirm('询问','你确认要删除记录吗?',function(r){
            if (r){
            	for (var i = rows.length - 1; i >= 0; i--) {
            		printLog(rows[i]);
            		var index = codeModelMapSetList.datagrid('getRowIndex', rows[i]);
            		codeModelMapSetList.datagrid('deleteRow', index);
            	}
            }
        });
    }else {
    	showMsg("请选择操作记录.");
    }
}

function saveModelMapInfo() {
	var rows = codeModelMapSetList.datagrid('getRows');
	var modelMapInfo = [{
		id:${(modelTable.id)!},
		moduleName:$('#editModuleName').val(),
		modelName:$('#editModelName').val(),
		tableName:$('#editTableName').val(),
		comment:$('#editComment').val(),
		listOperationBtn:$('#editListOperationBtn').val(),
		mappedItems:rows
	}];
	printLog(modelMapInfo);
	$.post("codeCreater.do?saveSetMap", {data:JSON.stringify(modelMapInfo)}, function(result) {
           if(result.success){
        	  showMsg('保存成功.');
        	  reloadModelTable();
           }else {
        	   showMsg('保存失败.');  
           }
   }, "JSON");
}
</script>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region: 'north', border:false" >
		<table cellpadding="5">
			<input name="id" id="editModelTableId" type="hidden" value="${(modelTable.id)!}" />
			<input id="editListOperationBtn" type="hidden" value="${(modelTable.listOperationBtn)!}" />
			
			<tr>
				<td class="tbW">模块名称(英文):</td>
				<td>
					<input id="editModuleName" name="moduleName" style="width:300px;" class="easyui-validatebox textbox" data-options="required: true, width: 150" value="${(modelTable.moduleName)!}" />
				</td>
				<td class="tbW">模型名称(英文):</td>
				<td>
					<input id="editModelName" name="modelName" style="width:300px;"  class="easyui-validatebox textbox" data-options="required: true, width: 150" value="${(modelTable.modelName)!}" />
				</td>
			</tr>
			<tr>
				
			</tr>
			<tr>
				<td class="tbW">表名:</td>
				<td>
					<input id="editTableName" name="tableName" style="width:300px;" class="easyui-validatebox textbox" data-options="required: true, width: 150" value="${(modelTable.tableName)!}" />
				</td>
				<td class="tbW">说明:</td>
				<td>
					<input id="editComment" name="comment" style="width:300px;" class="easyui-validatebox textbox" data-options="width: 150" value="${(modelTable.comment)!}" />
				</td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',border:false">
		<@eu.datagrid id="codeModelMapSetList" title="表映射关系设置" toolbar="#codeModelMapSetToolbar" idField="id" autoEditing="true" singleEditing="true" extEditing="true"
			 url="codeCreater.do?loadModelMaps&tableId=${(modelTable.id)!}" rownumbers="false" pagination="false"
			 item="com.xdtech.coder.vo.ModelTableMappedItem"/>
			 
		<div id="codeModelMapSetToolbar">
			<@eu.linkbutton showName="新增" iconCls="icon-add" onclick="addModelMap()"/>
			<@eu.linkbutton showName="删除" iconCls="icon-remove" onclick="removeModelMap()"/>
		</div>
	</div>
</div>
